﻿using System.Windows;
using OAuth.Providers.ETrade;

namespace OAuth.Samples.ETrade
{

    public partial class FrmLoginWeb
    {

        private readonly Identity _identity;

        public FrmLoginWeb(Identity identity)
        {
            InitializeComponent();

            _identity = identity;
            _identity.RequestTokenCompleted += IdentityRequestTokenCompleted;
            _identity.AccessTokenCompleted += IdentityAccessTokenCompleted;

            Loaded += MainWindowLoaded;
        }

        private void MainWindowLoaded(object sender, RoutedEventArgs e)
        {
            _identity.GetRequestToken();
        }

        private void IdentityRequestTokenCompleted(string value)
        {
            webBrowser.Navigate(value);
        }

        private void BtValidatePinClick(object sender, RoutedEventArgs e)
        {
            _identity.GetAccessToken(txtPin.Text);
        }

        private void IdentityAccessTokenCompleted()
        {
            DialogResult = true;
        }

    }

}